package com.bootMybatis.utils;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public enum CreateXjBankFile {

	INSTANCE;

	public void writeFile(List<Map<String, Object>> list, String fileName, String nameSpace) throws Exception {
		char separator = 0x02;
		StringBuffer content = new StringBuffer();
		for (Map<String, Object> map : list) {
			StringBuffer buffer = new StringBuffer();
			for (Entry<String, Object> entry : map.entrySet()) {
				Object value = entry.getValue();
				if (value == null) {
					value = "";
				}
				buffer.append(value + String.valueOf(separator));
			}
			content.append(buffer.substring(0, buffer.length() - 1) + "\n");
		}
		writeFile(content.toString(), fileName, nameSpace);
	}

	private void writeFile(String content, String fileName, String path) throws Exception {
		ThreadWriteFile writeFile = new ThreadWriteFile(content, fileName, ".txt", path);
		writeFile.writeFile();
	}
}
